#例6-1
student_1ist =[("name ","小千"),("stuid","202201"),("grade","大二")]
student dict-dict (student list) 
print(student_dict)

#例6-2
student dict =dict(name="小千",stuid="202201",grade-"大二") 
print (student_dict)

//例6-3
student dict ={"name":"小千","stuid":"202201","grade":"大二"}
print ("学号为:",student dict["stu id"])

//例6-4
student dict ={"name":"小千","stuid":"202201","grade":"大二"}
2 Score value =student dict.get("score","此键不存在")
print (score_value)

#例6-5
C_dict -{ 
    "小千":"狮子座", 
"小锋":"金牛座", 
"小扣":"金牛座", 
"小丁":"处女座", 
}
for item in C_dict.items (): 
print (item)

#例6-6
C_dict -{ 
    "小千":"狮子座", 
"小锋":"金牛座", 
"小扣":"金牛座", 
"小丁":"处女座", 
}
for key, value in C dict.items ():
print(f"(key)的星座是[value]")

#例6-7
C_dict -{ 
    "小千":"狮子座", 
"小锋":"金牛座", 
"小扣":"金牛座", 
"小丁":"处女座", 
}
for name in C dict.keys (): 
print (name)

#例6-8
C_dict -{ 
    "小千":"狮子座", 
"小锋":"金牛座", 
"小扣":"金牛座", 
"小丁":"处女座", 
}
if"张三"not in C dict.keys(): 
此后再按国8 print("张三没有参与星座讨论！")

#例6-9
C_dict -{ 
    "小千":"狮子座", 
"小锋":"金牛座", 
"小扣":"金牛座", 
"小丁":"处女座", 
}
for cons in c dict,values ():
print(cons)

#例6-10
C_dict -{ 
    "小千":"狮子座", 
"小锋":"金牛座", 
"小扣":"金牛座", 
"小丁":"处女座", 
}
for cons in set (C dict.values ()): 
print(cons)

#例6-11
student dict ={"name":"小千","stu_id":"202201","grade":"大二"}
if "name" in student dict: 
print("字典中含有1name '键") 
else: 
print("字典中没有name1键")

#例6-12
person_dict=("name":"小千","age":20)
person dict["name"] ="小锋"
print (person_dict)

#例6-13
person dict={"name":"小千","age":20} 
person_dict["grade"]="大二" 
print(person dict)

#例6-14
person dict={"name":"小千","age":20}
value =person dict.setdefault("grade","大二") 
print(f"返回值:(value),字典:iperson_dict")

#例6-15
person dict =["name":"小千","age":20] 
value= person_dict..setdefault("name","小锋") 
print(E"返回值:7value1,字典:Iperson dict")

#例6-16
person dict =["name":"小千","age":20] 
del person dict["age"] 
print (person dict)

#例6-17
goods dict= {
"牛奶":20, 
"杯子":10, 
"薯片":20, 
}
latest goods -goods dict.copy() 
latest goods ["牛奶"]+=10 
print("原货架商品信息:", goods_dict) 
print("现货架商品信息:", latest_goods)

#例6-18
dict01={"a":1,"b":2} 
dict02={"a":3,"d":4} 
dict01.update(dict02) 
print(dict01)

#例6-19
dict01={"a":1, "b":2}
dict02={"a":3,"d":4} 
dict03 ={**dict01,**dict02}
print (dict03)

#例6-20
dict01={"a":1, "b":2}
dict02={"a":3,"d":4} 
dict03=dict01|dict02 
print(dict03)

#例6-21
dict01={"a":1, "b":2}
dict02={"a":3,"d":4} 
dict01|=dict02 
print(dict01)

#例6-22
square dict={} 
fori in range (1,6): 
square dictlil -i**2 
print (square dict)

#例6-23
person_list=[("小千",20),("小锋",19),("小扣",17),("小丁",18)] 
teenager dict={}
for name,age in person list: 
if age <18: 
teenager dict [name]-age 
print (teenager dict)

#例6-24
waste dict={
"可回收垃圾":["玻璃","金属" "塑料瓶", "纸张","衣服"], 
"干垃圾":["餐巾纸", "塑料袋","纸巾","纸尿裤", "花盆", "陶瓷"], 
"湿垃圾":["剩饭剩菜","瓜皮果核", "花卉绿植","过期食品"], 
"有害垃圾":["电池","油漆桶", "荧光灯管","废药品"], 
}

#例6-25
while True: 
search_waste=input ("请输入您要查询的垃圾:") 
find- False 
if search waste-"q": 11 break 
for classify, waste in waste dict.items (): 
if search waste in waste: 
find- True  
print(f"[search Waste]的类别是[classify]")  
print ("-"*30) 
if find-False: 
18 print("没有找到该垃圾的分类，请自行判断") 
print("-"*30) 
for classify,waste in waste dict.items (): 
print(f"(classify)包括:",end=-"")  
for item in waste:  
if waste.index(item)- len (waste)-1:  
print(item) else: 
print(item, end-",") 
print ("-"*30) 
break 

#例6-26
while True: 
option=input("您是否希望将此垃圾加入现有分类中呢(yes/no)?") 
if option -"yes": 
classify =input ("您希望将垃圾加入哪个类别？") 
try: 
waste dict[classify].append (search_waste)
except KeyError: 
print ("您的输入有误，没有此类别") 
break 
elif option-"no": 
print ("可以继续查询垃圾分类") 
break 
else: 
print("您的输入有误，请重新输入")

#例6-27
import jieba 
cut_list=ieba.lcut("为中华之崛起而读书") 
print (cut _list)

#例6-28
from jieba import * 
sentence="同一性是指矛盾双方相互依存、相互贯通的性质和趋势" 
list01= lcut (sentence)
list02-lcut(sentence,cut a11-True) 
list03= lcut for search (sentence) 
print (f"精确模式分词结果为{1ist01}") 
print (f"全模式分词结果为{1ist02}") 
print(f"搜索引擎模式分词结果为{1ist 03}")

#例6-29
import jieba 
sentence ="千锋教育一直秉持'用良心做教育'的理念" 
word_list = jieba.lcut (sentence) 
print(word_list)

#例6-30
import jieba 
sentence="千锋教育一直秉持'用良心做教育'的理念" 
jieba.add_word("千锋教育") 
word_list = jieba.lcut(sentence) 
print (word_list)

#例6-31
import jieba 
sentence="千锋教育一直秉持'用良心做教育'的理念" 
jieba.del word("理念") 
word_list = jieba.lcut(sentence) 
print (word_list)

#例6-32
import jieba.analyse congcong text=""" 
去的尽管去了，来的尽管来着；去来的中间，又怎样地匆匆呢？早上我起来的时候， 小屋里射进两三方斜斜的太阳。太阳他有脚啊，轻轻悄悄地挪移了；我也茫茫然跟着旋转。于是--洗手的时候，日子从水盆里过去；吃饭的时候，日子从饭碗里过去； 默默时，便从凝然的双眼前过去。我觉察他去的匆匆了，伸出手遮挽时，他又从遮挽着的手边过去，天黑时，我躺在床上，他便伶伶俐俐地从我身上跨过，从我脚边飞去了。等我睁开眼和太阳再见，这算又溜走了一日。我掩着面叹息。但是新来的日子的影儿又开始在叹息里闪过了。 
""" 
keywords= jieba.analyse.extract_tags (congcong text,topk=5) 
print (keywords)

#例6-33
import jieba 
with open ("comment.txt", "r",encoding-"utf-8") as f: 
text-f.read () 
comment_words - jieba.lcut (text) 
comment_dict={}
for word in comment_words: 
if len (word)==1: 
continue 
else: 
comment dict[word]-comment dict.get (word,0)+1 
sort_list=sorted (comment_dict.items (), key=lambda x:x[1], reverse=True) 
for i in range (15): 
word, count -sort list[i] 
print (f"{word:^10}{count:^10}")

#例6-34
import jieba 
result=jieba.lcut ("太酸涩了，不好吃，严重与描述不符") 
print (result)

#例6-35
import jieba 
jieba.add Word("不好吃") 
result=jieba.lcut ("太酸涩了，不好吃，严重与描述不符") 
print (result)

#例6-36
import jieba 
text-open ("comment.txt","r", encoding-"utf-8").read () 
jieba.add_word("不好吃") 
jieba.add_word("不新鲜") 
jieba.add_word("不喜欢") 
comment_words=jieba.lcut(text) 
comment_dict={} 
for word in comment words: 
if len (word)==1: 
continue 
else: 
comment_dict [word]=comment_dict.get (word,0)+1 
sort_list=sorted (comment_dict.items (), key-lambda x:x[1],reverse-True) 
for i in range (15): 
word,count=sort list[i] 
print (f"{word:^10}{count:^10}")

#例6-37
dict01={} 
print("{}的类型是:",type (dict01)) 
set01 =["小千","小锋"] 
print ("set01的类型是",type(set01))

#例6-38
set01=["小千","小锋","小千"] 
print(set01)

#例6-39
set01-set ("qianfeng") 
set02=set(("小千","小锋")) 
set03=set(["小千", "小锋"]) 
set04=set({"小千":19,"小锋":18}) 
print("set01:", set01) 
print("set02:", set02) 
print("set03:", set03) 
print("set04:", set04)

#例6-40
language_set ={"汉语","英语","法语"} 
language_set.add ("俄语") 
print (language_set)

#例6-41
language_set ={"汉语"，"英语"，"法语"}
language_set.discard("英语") 
print(language_set) 
language_set.remove ("法语")  
print(language_set)

#例6-42
set01={1,2,3,4}
set02={3,4,5,6} 
print ("set01&set02:", set01&set02) 
print ("set01|set02:", set01|set02) 
print("set01-set02:", set01-set02) 
print("set01^set02:", set01^set02)
